<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"vchao.top","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="# 需求 接手的公司的一个项目，有一个需求是折线图可以通过上下滑动改变数值。原先的大佬自己从头写的，也能实现功能。大佬后来也把思路和代码分享出来了。大家有兴趣的可以看一下。手把手教你写一个可以上下滑动点改变值的安卓折线图 因为后来需求有些变动，原来的代码改动起来略显吃力，于是自己又以hellocharts为基础重新封装了一个自定义VIew，以此来实现功能。使用起来也更简洁一些。 需求明确：  多">
<meta property="og:type" content="article">
<meta property="og:title" content="安卓可上下滑动改变数值的折线图（基于hellochart）">
<meta property="og:url" content="http://vchao.top/2021/08/25/%E5%AE%89%E5%8D%93%E5%8F%AF%E4%B8%8A%E4%B8%8B%E6%BB%91%E5%8A%A8%E6%94%B9%E5%8F%98%E6%95%B0%E5%80%BC%E7%9A%84%E6%8A%98%E7%BA%BF%E5%9B%BE%EF%BC%88%E5%9F%BA%E4%BA%8Ehellochart%EF%BC%89/index.html">
<meta property="og:site_name" content="乘风破浪">
<meta property="og:description" content="# 需求 接手的公司的一个项目，有一个需求是折线图可以通过上下滑动改变数值。原先的大佬自己从头写的，也能实现功能。大佬后来也把思路和代码分享出来了。大家有兴趣的可以看一下。手把手教你写一个可以上下滑动点改变值的安卓折线图 因为后来需求有些变动，原来的代码改动起来略显吃力，于是自己又以hellocharts为基础重新封装了一个自定义VIew，以此来实现功能。使用起来也更简洁一些。 需求明确：  多">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20190525193108723.gif">
<meta property="article:published_time" content="2021-08-25T14:42:51.158Z">
<meta property="article:modified_time" content="2021-08-25T14:37:20.800Z">
<meta property="article:author" content="vchao">
<meta property="article:tag" content="Android">
<meta property="article:tag" content="hellochart">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/20190525193108723.gif">

<link rel="canonical" href="http://vchao.top/2021/08/25/%E5%AE%89%E5%8D%93%E5%8F%AF%E4%B8%8A%E4%B8%8B%E6%BB%91%E5%8A%A8%E6%94%B9%E5%8F%98%E6%95%B0%E5%80%BC%E7%9A%84%E6%8A%98%E7%BA%BF%E5%9B%BE%EF%BC%88%E5%9F%BA%E4%BA%8Ehellochart%EF%BC%89/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>安卓可上下滑动改变数值的折线图（基于hellochart） | 乘风破浪</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">乘风破浪</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://vchao.top/2021/08/25/%E5%AE%89%E5%8D%93%E5%8F%AF%E4%B8%8A%E4%B8%8B%E6%BB%91%E5%8A%A8%E6%94%B9%E5%8F%98%E6%95%B0%E5%80%BC%E7%9A%84%E6%8A%98%E7%BA%BF%E5%9B%BE%EF%BC%88%E5%9F%BA%E4%BA%8Ehellochart%EF%BC%89/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="vchao">
      <meta itemprop="description" content="怀揣好奇，梦想改变世界的菜鸟极客">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="乘风破浪">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          安卓可上下滑动改变数值的折线图（基于hellochart）
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2021-08-25 22:42:51 / 修改时间：22:37:20" itemprop="dateCreated datePublished" datetime="2021-08-25T22:42:51+08:00">2021-08-25</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Android/" itemprop="url" rel="index"><span itemprop="name">Android</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>﻿# 需求</p>
<p>接手的公司的一个项目，有一个需求是折线图可以通过上下滑动改变数值。原先的大佬自己从头写的，也能实现功能。大佬后来也把思路和代码分享出来了。大家有兴趣的可以看一下。<br><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/cdf55a956beb">手把手教你写一个可以上下滑动点改变值的安卓折线图</a><br> 因为后来需求有些变动，原来的代码改动起来略显吃力，于是自己又以hellocharts为基础重新封装了一个自定义VIew，以此来实现功能。使用起来也更简洁一些。</p>
<p><strong>需求明确：</strong></p>
<ul>
<li>多条折线图切换滑动</li>
<li>手动上下滑动改变数值</li>
</ul>
<h1 id="实现效果图"><a href="#实现效果图" class="headerlink" title="实现效果图"></a>实现效果图</h1><p><img src="https://img-blog.csdnimg.cn/20190525193108723.gif" alt="滑动折线图"></p>
<h1 id="分析"><a href="#分析" class="headerlink" title="分析"></a>分析</h1><p>现在最好用的图表库大概就是hellochart了。但是hellochart并没有提供滑动改变数值的接口以及相关内容。因此我们在hellochart的基础上进行功能扩展，通过自定义控件来实现如图效果。<br>首先需要确定用户点击的是哪一条线，哪一个点。然后对对应的数据进行操作。重新进行赋值改变图表显示。</p>
<h1 id="实现"><a href="#实现" class="headerlink" title="实现"></a>实现</h1><h2 id="尺寸计算"><a href="#尺寸计算" class="headerlink" title="尺寸计算"></a>尺寸计算</h2><p>首先计算控件宽高，因为要滑动，不宜进行1：1的计算，滑动难度高。因此乘以0.75，以方便响应用户手势操作。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">int</span> width = getMeasuredWidth() - getPaddingLeft() - getPaddingRight();</span><br><span class="line"><span class="keyword">int</span> height = getMeasuredHeight() - getPaddingTop() - getPaddingBottom();</span><br><span class="line"></span><br><span class="line">hLength = width * <span class="number">0.75f</span>;          <span class="comment">// x轴长度</span></span><br><span class="line">vLength = height * <span class="number">0.75f</span>;         <span class="comment">// y轴长度</span></span><br></pre></td></tr></table></figure>
<h2 id="触摸-按下响应事件"><a href="#触摸-按下响应事件" class="headerlink" title="触摸 - 按下响应事件"></a>触摸 - 按下响应事件</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">lineChartData = vccharts.<span class="keyword">this</span>.getLineChartData();</span><br><span class="line"></span><br><span class="line">                <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; lineChartData.getLines().size(); i++) &#123;</span><br><span class="line">                    Line line = lineChartData.getLines().get(i);</span><br><span class="line">                    <span class="keyword">int</span> pointRadius = ChartUtils.dp2px(density, line.getPointRadius());</span><br><span class="line">                    <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; line.getValues().size(); j++) &#123;</span><br><span class="line">                        PointValue pointValue = line.getValues().get(j);</span><br><span class="line">                        <span class="keyword">final</span> <span class="keyword">float</span> rawValueX = vccharts.<span class="keyword">this</span>.getChartComputator().computeRawX(pointValue.getX());</span><br><span class="line">                        <span class="keyword">final</span> <span class="keyword">float</span> rawValueY = vccharts.<span class="keyword">this</span>.getChartComputator().computeRawY(pointValue.getY());</span><br><span class="line">                        <span class="keyword">if</span> (isInArea(rawValueX, rawValueY, touchX, touchY, pointRadius + touchToleranceMargin)) &#123;</span><br><span class="line">                            LogUtils.e(<span class="string">&quot;     xuanzhong   xxx &quot;</span> + pointValue.getX() + <span class="string">&quot;        yyy   &quot;</span> + pointValue.getY() + <span class="string">&quot;           &quot;</span>);</span><br><span class="line">                            vccharts.<span class="keyword">this</span>.lineIndex = i;</span><br><span class="line">                            vccharts.<span class="keyword">this</span>.pointIndex = j;</span><br><span class="line">                            isMoveChange = <span class="keyword">true</span>;</span><br><span class="line">                            <span class="keyword">for</span> (Line line1 : lineChartData.getLines()) &#123;</span><br><span class="line">                                line1.setStrokeWidth(<span class="number">2</span>);</span><br><span class="line">                            &#125;</span><br><span class="line">                            line.setStrokeWidth(<span class="number">4</span>);</span><br><span class="line">                            selectLineNumber = i;</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br></pre></td></tr></table></figure>
<h2 id="触摸-移动响应事件"><a href="#触摸-移动响应事件" class="headerlink" title="触摸 - 移动响应事件"></a>触摸 - 移动响应事件</h2><p>移动的时候需要判断位移以及差值，重新计算比例，确定新数值，进而更新数据，刷新View显示。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">                    <span class="keyword">float</span> y_max = <span class="number">10</span>;</span><br><span class="line">                    <span class="keyword">float</span> y_min = <span class="number">0</span>;</span><br><span class="line"><span class="comment">//                    如果没有选中任何点</span></span><br><span class="line">                    <span class="keyword">if</span> (pointIndex == -<span class="number">1</span> || lineIndex == -<span class="number">1</span>) &#123;</span><br><span class="line">                        <span class="keyword">return</span> <span class="keyword">super</span>.onTouchEvent(event);</span><br><span class="line">                    &#125;</span><br><span class="line">                    lineChartData = vccharts.<span class="keyword">this</span>.getLineChartData();</span><br><span class="line">                    <span class="keyword">float</span> y = lineChartData.getLines().get(lineIndex).getValues().get(pointIndex).getY();</span><br><span class="line">                    <span class="keyword">float</span> x = lineChartData.getLines().get(lineIndex).getValues().get(pointIndex).getX();</span><br><span class="line">                    <span class="keyword">float</span> y_new = y_max - coordinateConversionY(touchY);</span><br></pre></td></tr></table></figure>
<p>数值保护，防止超过数据边界</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> (y_new &lt; y_pre) &#123;</span><br><span class="line">       y_new = y_pre;</span><br><span class="line"> &#125;</span><br><span class="line"><span class="keyword">if</span> (y_new &gt; y_after) &#123;</span><br><span class="line">       y_new = y_after;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">if</span> (y_new &lt; y_min) &#123;</span><br><span class="line">        y_new = y_min;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">if</span> (y_new &gt; y_max) &#123;</span><br><span class="line">       y_new = y_max;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>重新设置数据，通知数据变化</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">lineChartData.getLines().get(lineIndex).getValues().get(pointIndex).set(x, y_new);</span><br><span class="line"><span class="comment">// 通知数据变化</span></span><br><span class="line"> postInvalidate();</span><br></pre></td></tr></table></figure>
<h2 id="触摸-抬起事件"><a href="#触摸-抬起事件" class="headerlink" title="触摸 - 抬起事件"></a>触摸 - 抬起事件</h2><p>抬起的时候，取消选择的线条的状态，并且计算最终数据，进行显示</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> (vccharts.<span class="keyword">this</span>.pointIndex == -<span class="number">1</span> || vccharts.<span class="keyword">this</span>.lineIndex == -<span class="number">1</span>) &#123;</span><br><span class="line">                        isMoveChange = <span class="keyword">false</span>;</span><br><span class="line">                        <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">                    &#125;</span><br><span class="line"></span><br><span class="line">                    <span class="comment">//                    通知数据变化</span></span><br><span class="line">                    List&lt;PointValue&gt; values = lineChartData.getLines().get(lineIndex).getValues();</span><br><span class="line">                    <span class="keyword">float</span>[] changeData = <span class="keyword">new</span> <span class="keyword">float</span>[values.size()];</span><br><span class="line">                    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; values.size(); i++) &#123;</span><br><span class="line">                        changeData[i] = values.get(i).getY();</span><br><span class="line">                    &#125;</span><br><span class="line"></span><br><span class="line">                    <span class="keyword">try</span> &#123;</span><br><span class="line">                        <span class="keyword">if</span> (vcListener != <span class="keyword">null</span>) &#123;</span><br><span class="line">                            vcListener.DataChange(lineIndex, <span class="keyword">new</span> ZuniData(changeData));</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">                        e.printStackTrace();</span><br><span class="line">                    &#125;</span><br><span class="line"></span><br><span class="line">                    postInvalidate();</span><br><span class="line"></span><br><span class="line">                    isMoveChange = <span class="keyword">false</span>;</span><br><span class="line">                    vccharts.<span class="keyword">this</span>.pointIndex = -<span class="number">1</span>;</span><br><span class="line">                    vccharts.<span class="keyword">this</span>.lineIndex = -<span class="number">1</span>;</span><br><span class="line">                    <span class="keyword">return</span> <span class="keyword">true</span>;</span><br></pre></td></tr></table></figure>
<h2 id="判断是否点击对应点"><a href="#判断是否点击对应点" class="headerlink" title="判断是否点击对应点"></a>判断是否点击对应点</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">boolean</span> <span class="title">isInArea</span><span class="params">(<span class="keyword">float</span> x, <span class="keyword">float</span> y, <span class="keyword">float</span> touchX, <span class="keyword">float</span> touchY, <span class="keyword">float</span> radius)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">float</span> diffX = touchX - x;</span><br><span class="line">    <span class="keyword">float</span> diffY = touchY - y;</span><br><span class="line">    <span class="keyword">return</span> Math.pow(diffX, <span class="number">2</span>) + Math.pow(diffY, <span class="number">2</span>) &lt;= <span class="number">2</span> * Math.pow(radius, <span class="number">2</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


<h1 id="完整代码："><a href="#完整代码：" class="headerlink" title="完整代码："></a>完整代码：</h1><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">vccharts</span> <span class="keyword">extends</span> <span class="title">LineChartView</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="keyword">int</span> DEFAULT_TOUCH_TOLERANCE_MARGIN_DP = <span class="number">4</span>;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">final</span> ChartTouchHandler0 touchHandler0;</span><br><span class="line">    <span class="keyword">boolean</span> isMoveChange = <span class="keyword">false</span>; <span class="comment">// 是否需要根据移动改变</span></span><br><span class="line">    <span class="keyword">boolean</span> isBetterPreAfter = <span class="keyword">true</span>; <span class="comment">// 是否需要比较前后</span></span><br><span class="line">    <span class="keyword">int</span> pointIndex;</span><br><span class="line">    <span class="keyword">int</span> lineIndex;</span><br><span class="line">    <span class="keyword">private</span> LineChartData lineChartData;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">float</span> vLength;<span class="comment">// 竖线长度</span></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">float</span> hLength;<span class="comment">// 横线长度</span></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">float</span> density;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">int</span> touchToleranceMargin;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">int</span> moveNumber = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">int</span> selectLineNumber = -<span class="number">1</span>; <span class="comment">// 现在选中的线条</span></span><br><span class="line">    <span class="keyword">private</span> vcDataChangeListener vcListener;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">vccharts</span><span class="params">(Context context, AttributeSet attrs)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">super</span>(context, attrs);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            density = context.getResources().getDisplayMetrics().density;</span><br><span class="line">            touchToleranceMargin = ChartUtils.dp2px(density, DEFAULT_TOUCH_TOLERANCE_MARGIN_DP);</span><br><span class="line">            LogUtils.e(<span class="string">&quot;  touchToleranceMargin  &quot;</span> + touchToleranceMargin);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">        touchHandler0 = <span class="keyword">new</span> ChartTouchHandler0(context, <span class="keyword">this</span>);</span><br><span class="line">        vccharts.<span class="keyword">this</span>.post(<span class="keyword">new</span> Runnable() &#123;</span><br><span class="line"></span><br><span class="line">            <span class="meta">@Override</span></span><br><span class="line">            <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">run</span><span class="params">()</span> </span>&#123;</span><br><span class="line">                <span class="comment">//在此处调用view.getMeasuredWidth()和getMeasuredHeight（）可得到正确值</span></span><br><span class="line">                <span class="keyword">int</span> width = getMeasuredWidth() - getPaddingLeft() - getPaddingRight();</span><br><span class="line">                <span class="keyword">int</span> height = getMeasuredHeight() - getPaddingTop() - getPaddingBottom();</span><br><span class="line"></span><br><span class="line">                hLength = width * <span class="number">0.75f</span>;          <span class="comment">// x轴长度</span></span><br><span class="line">                vLength = height * <span class="number">0.75f</span>;         <span class="comment">// y轴长度</span></span><br><span class="line"></span><br><span class="line">                LogUtils.e(<span class="string">&quot;  vLength &quot;</span> + vLength + <span class="string">&quot;  h &quot;</span> + hLength);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setVcListener</span><span class="params">(vcDataChangeListener vcListener)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.vcListener = vcListener;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">onTouchEvent</span><span class="params">(MotionEvent event)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">float</span> touchY = event.getY();</span><br><span class="line">        <span class="keyword">float</span> touchX = event.getX();</span><br><span class="line"></span><br><span class="line">        <span class="keyword">switch</span> (event.getAction()) &#123;</span><br><span class="line">            <span class="keyword">case</span> MotionEvent.ACTION_DOWN:</span><br><span class="line">                LogUtils.e(<span class="string">&quot;                 按下了  &quot;</span>);</span><br><span class="line"></span><br><span class="line">                moveNumber = <span class="number">0</span>;</span><br><span class="line">                lineChartData = vccharts.<span class="keyword">this</span>.getLineChartData();</span><br><span class="line"></span><br><span class="line">                <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; lineChartData.getLines().size(); i++) &#123;</span><br><span class="line">                    Line line = lineChartData.getLines().get(i);</span><br><span class="line">                    <span class="keyword">int</span> pointRadius = ChartUtils.dp2px(density, line.getPointRadius());</span><br><span class="line">                    <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; line.getValues().size(); j++) &#123;</span><br><span class="line">                        PointValue pointValue = line.getValues().get(j);</span><br><span class="line">                        <span class="keyword">final</span> <span class="keyword">float</span> rawValueX = vccharts.<span class="keyword">this</span>.getChartComputator().computeRawX(pointValue.getX());</span><br><span class="line">                        <span class="keyword">final</span> <span class="keyword">float</span> rawValueY = vccharts.<span class="keyword">this</span>.getChartComputator().computeRawY(pointValue.getY());</span><br><span class="line">                        <span class="keyword">if</span> (isInArea(rawValueX, rawValueY, touchX, touchY, pointRadius + touchToleranceMargin)) &#123;</span><br><span class="line">                            LogUtils.e(<span class="string">&quot;     xuanzhong   xxx &quot;</span> + pointValue.getX() + <span class="string">&quot;        yyy   &quot;</span> + pointValue.getY() + <span class="string">&quot;           &quot;</span>);</span><br><span class="line">                            vccharts.<span class="keyword">this</span>.lineIndex = i;</span><br><span class="line">                            vccharts.<span class="keyword">this</span>.pointIndex = j;</span><br><span class="line">                            isMoveChange = <span class="keyword">true</span>;</span><br><span class="line">                            <span class="keyword">for</span> (Line line1 : lineChartData.getLines()) &#123;</span><br><span class="line">                                line1.setStrokeWidth(<span class="number">2</span>);</span><br><span class="line">                            &#125;</span><br><span class="line">                            line.setStrokeWidth(<span class="number">4</span>);</span><br><span class="line">                            selectLineNumber = i;</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">            <span class="keyword">case</span> MotionEvent.ACTION_MOVE:</span><br><span class="line">                <span class="keyword">if</span> (isMoveChange) &#123;</span><br><span class="line">                    <span class="keyword">float</span> y_max = <span class="number">10</span>;</span><br><span class="line">                    <span class="keyword">float</span> y_min = <span class="number">0</span>;</span><br><span class="line"><span class="comment">//                    如果没有选中任何点</span></span><br><span class="line">                    <span class="keyword">if</span> (pointIndex == -<span class="number">1</span> || lineIndex == -<span class="number">1</span>) &#123;</span><br><span class="line">                        <span class="keyword">return</span> <span class="keyword">super</span>.onTouchEvent(event);</span><br><span class="line">                    &#125;</span><br><span class="line">                    lineChartData = vccharts.<span class="keyword">this</span>.getLineChartData();</span><br><span class="line">                    <span class="keyword">float</span> y = lineChartData.getLines().get(lineIndex).getValues().get(pointIndex).getY();</span><br><span class="line">                    <span class="keyword">float</span> x = lineChartData.getLines().get(lineIndex).getValues().get(pointIndex).getX();</span><br><span class="line">                    <span class="keyword">float</span> y_new = y_max - coordinateConversionY(touchY);</span><br><span class="line">                    <span class="keyword">if</span> (isBetterPreAfter) &#123;</span><br><span class="line">                        <span class="keyword">float</span> y_pre = y_min;</span><br><span class="line">                        <span class="keyword">float</span> y_after = y_max;</span><br><span class="line">                        <span class="keyword">if</span> (pointIndex &lt; lineChartData.getLines().get(lineIndex).getValues().size() - <span class="number">1</span>) &#123;</span><br><span class="line">                            y_after = lineChartData.getLines().get(lineIndex).getValues().get(pointIndex + <span class="number">1</span>).getY();</span><br><span class="line">                        &#125;</span><br><span class="line">                        <span class="keyword">if</span> (pointIndex &gt; <span class="number">0</span>) &#123;</span><br><span class="line">                            y_pre = lineChartData.getLines().get(lineIndex).getValues().get(pointIndex - <span class="number">1</span>).getY();</span><br><span class="line">                        &#125;</span><br><span class="line">                        <span class="keyword">if</span> (y_new &lt; y_pre) &#123;</span><br><span class="line">                            y_new = y_pre;</span><br><span class="line">                        &#125;</span><br><span class="line">                        <span class="keyword">if</span> (y_new &gt; y_after) &#123;</span><br><span class="line">                            y_new = y_after;</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;</span><br><span class="line"></span><br><span class="line">                    <span class="keyword">if</span> (y_new &lt; y_min) &#123;</span><br><span class="line">                        y_new = y_min;</span><br><span class="line">                    &#125;</span><br><span class="line">                    <span class="keyword">if</span> (y_new &gt; y_max) &#123;</span><br><span class="line">                        y_new = y_max;</span><br><span class="line">                    &#125;</span><br><span class="line">                    lineChartData.getLines().get(lineIndex).getValues().get(pointIndex).set(x, y_new);</span><br><span class="line"><span class="comment">//                    通知数据变化</span></span><br><span class="line">                    <span class="comment">/*List&lt;PointValue&gt; values = lineChartData.getLines().get(lineIndex).getValues();</span></span><br><span class="line"><span class="comment">                    float[] changeData = new float[values.size()];</span></span><br><span class="line"><span class="comment">                    for (int i = 0; i &lt; values.size(); i++) &#123;</span></span><br><span class="line"><span class="comment">                        changeData[i] = values.get(i).getY();</span></span><br><span class="line"><span class="comment">                    &#125;*/</span></span><br><span class="line">                    postInvalidate();</span><br><span class="line">                    <span class="comment">/*if (vcListener != null) &#123;</span></span><br><span class="line"><span class="comment">                        moveNumber++;</span></span><br><span class="line"><span class="comment">                        if (moveNumber % 3 == 0) &#123;</span></span><br><span class="line"><span class="comment">                            vcListener.DataChange(lineIndex, new ZuniData(changeData));</span></span><br><span class="line"><span class="comment">                        &#125;</span></span><br><span class="line"><span class="comment">                    &#125;*/</span></span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">return</span> <span class="keyword">super</span>.onTouchEvent(event);</span><br><span class="line">            <span class="keyword">case</span> MotionEvent.ACTION_UP:</span><br><span class="line">                LogUtils.e(<span class="string">&quot;  move &quot;</span> + moveNumber);</span><br><span class="line">                <span class="keyword">if</span> (isMoveChange) &#123;</span><br><span class="line">                    <span class="keyword">if</span> (vccharts.<span class="keyword">this</span>.pointIndex == -<span class="number">1</span> || vccharts.<span class="keyword">this</span>.lineIndex == -<span class="number">1</span>) &#123;</span><br><span class="line">                        isMoveChange = <span class="keyword">false</span>;</span><br><span class="line">                        <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">                    &#125;</span><br><span class="line"></span><br><span class="line">                    <span class="comment">//                    通知数据变化</span></span><br><span class="line">                    List&lt;PointValue&gt; values = lineChartData.getLines().get(lineIndex).getValues();</span><br><span class="line">                    <span class="keyword">float</span>[] changeData = <span class="keyword">new</span> <span class="keyword">float</span>[values.size()];</span><br><span class="line">                    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; values.size(); i++) &#123;</span><br><span class="line">                        changeData[i] = values.get(i).getY();</span><br><span class="line">                    &#125;</span><br><span class="line"></span><br><span class="line">                    <span class="keyword">try</span> &#123;</span><br><span class="line">                        <span class="keyword">if</span> (vcListener != <span class="keyword">null</span>) &#123;</span><br><span class="line">                            vcListener.DataChange(lineIndex, <span class="keyword">new</span> ZuniData(changeData));</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">                        e.printStackTrace();</span><br><span class="line">                    &#125;</span><br><span class="line"></span><br><span class="line">                    postInvalidate();</span><br><span class="line"></span><br><span class="line">                    isMoveChange = <span class="keyword">false</span>;</span><br><span class="line">                    vccharts.<span class="keyword">this</span>.pointIndex = -<span class="number">1</span>;</span><br><span class="line">                    vccharts.<span class="keyword">this</span>.lineIndex = -<span class="number">1</span>;</span><br><span class="line">                    <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">            <span class="keyword">case</span> MotionEvent.ACTION_CANCEL:</span><br><span class="line">                <span class="keyword">if</span> (isMoveChange) &#123;</span><br><span class="line">                    isMoveChange = <span class="keyword">false</span>;</span><br><span class="line">                    vccharts.<span class="keyword">this</span>.pointIndex = -<span class="number">1</span>;</span><br><span class="line">                    vccharts.<span class="keyword">this</span>.lineIndex = -<span class="number">1</span>;</span><br><span class="line">                    <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">super</span>.onTouchEvent(event);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 把坐标从 y 轴的位置转换成实际的值</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">float</span> <span class="title">coordinateConversionY</span><span class="params">(<span class="keyword">float</span> y)</span> </span>&#123;</span><br><span class="line">        LogUtils.i(<span class="string">&quot;坐标从 y 轴的位置转换成实际的值&quot;</span> + (<span class="number">10</span> - <span class="number">0</span>) / vLength * y);</span><br><span class="line">        <span class="keyword">return</span> (<span class="number">10</span> - <span class="number">0</span>) / vLength * y;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 把坐标从 x 轴的位置转换成实际的值</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">float</span> <span class="title">coordinateConversionX</span><span class="params">(<span class="keyword">float</span> x)</span> </span>&#123;</span><br><span class="line">        LogUtils.i(<span class="string">&quot;坐标从 x 轴的位置转换成实际的值&quot;</span> + (<span class="number">11</span> - <span class="number">0</span>) / hLength * x);</span><br><span class="line">        <span class="keyword">return</span> (<span class="number">11</span> - <span class="number">0</span>) / hLength * x;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">boolean</span> <span class="title">isInArea</span><span class="params">(<span class="keyword">float</span> x, <span class="keyword">float</span> y, <span class="keyword">float</span> touchX, <span class="keyword">float</span> touchY, <span class="keyword">float</span> radius)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">float</span> diffX = touchX - x;</span><br><span class="line">        <span class="keyword">float</span> diffY = touchY - y;</span><br><span class="line">        <span class="keyword">return</span> Math.pow(diffX, <span class="number">2</span>) + Math.pow(diffY, <span class="number">2</span>) &lt;= <span class="number">2</span> * Math.pow(radius, <span class="number">2</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getSelectLineNumber</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> selectLineNumber;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setSelectLineNumber</span><span class="params">(<span class="keyword">int</span> selectLineNumber)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.selectLineNumber = selectLineNumber;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">isBetterPreAfter</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> isBetterPreAfter;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setBetterPreAfter</span><span class="params">(<span class="keyword">boolean</span> betterPreAfter)</span> </span>&#123;</span><br><span class="line">        isBetterPreAfter = betterPreAfter;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">vcDataChangeListener</span> </span>&#123;</span><br><span class="line">        <span class="function"><span class="keyword">void</span> <span class="title">DataChange</span><span class="params">(<span class="keyword">int</span> line_index, ZuniData ZuniData)</span></span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Android/" rel="tag"># Android</a>
              <a href="/tags/hellochart/" rel="tag"># hellochart</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/08/25/%E3%80%90%E9%A1%B9%E7%9B%AE%E6%8E%A8%E8%8D%90%E3%80%91%E4%B8%80%E8%B5%B7%E6%9D%A5%E7%9C%8B%E4%B8%AA%E9%80%BC%E6%A0%BC%E5%84%BF%E5%BE%88%E9%AB%98%E7%9A%84%E4%B8%AA%E4%BA%BA%E7%AE%80%E5%8E%86%E9%A1%B9%E7%9B%AE/" rel="prev" title="【项目推荐】一起来看个逼格儿很高的个人简历项目">
      <i class="fa fa-chevron-left"></i> 【项目推荐】一起来看个逼格儿很高的个人简历项目
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/08/25/%E5%AE%89%E5%8D%93%E5%AF%BC%E5%87%BAExcel%EF%BC%8Ctxt%E6%96%87%E4%BB%B6%E5%B7%A5%E5%85%B7%E7%B1%BB/" rel="next" title="安卓导出Excel，txt文件工具类">
      安卓导出Excel，txt文件工具类 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%AE%9E%E7%8E%B0%E6%95%88%E6%9E%9C%E5%9B%BE"><span class="nav-number">1.</span> <span class="nav-text">实现效果图</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%88%86%E6%9E%90"><span class="nav-number">2.</span> <span class="nav-text">分析</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%AE%9E%E7%8E%B0"><span class="nav-number">3.</span> <span class="nav-text">实现</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%B0%BA%E5%AF%B8%E8%AE%A1%E7%AE%97"><span class="nav-number">3.1.</span> <span class="nav-text">尺寸计算</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%A7%A6%E6%91%B8-%E6%8C%89%E4%B8%8B%E5%93%8D%E5%BA%94%E4%BA%8B%E4%BB%B6"><span class="nav-number">3.2.</span> <span class="nav-text">触摸 - 按下响应事件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%A7%A6%E6%91%B8-%E7%A7%BB%E5%8A%A8%E5%93%8D%E5%BA%94%E4%BA%8B%E4%BB%B6"><span class="nav-number">3.3.</span> <span class="nav-text">触摸 - 移动响应事件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%A7%A6%E6%91%B8-%E6%8A%AC%E8%B5%B7%E4%BA%8B%E4%BB%B6"><span class="nav-number">3.4.</span> <span class="nav-text">触摸 - 抬起事件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E7%82%B9%E5%87%BB%E5%AF%B9%E5%BA%94%E7%82%B9"><span class="nav-number">3.5.</span> <span class="nav-text">判断是否点击对应点</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%AE%8C%E6%95%B4%E4%BB%A3%E7%A0%81%EF%BC%9A"><span class="nav-number">4.</span> <span class="nav-text">完整代码：</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">vchao</p>
  <div class="site-description" itemprop="description">怀揣好奇，梦想改变世界的菜鸟极客</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">46</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
        <span class="site-state-item-count">4</span>
        <span class="site-state-item-name">分类</span>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">27</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        
  <div class="beian"><a href="https://beian.miit.gov.cn/" rel="noopener" target="_blank">冀ICP备 17022751号-1 </a>
      <img src="https://beian.miit.gov.cn" style="display: inline-block;">
  </div>

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">vchao</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
